import uicls
import uiutil
import uitest
import uthread
import blue
import base
import trinity

class ContainerLayer(uicls.NewContainer, uicls._GetDecoMetaclassInst('trinity.Tr2Sprite2dLayer')):
    __guid__ = 'uitest.ContainerLayer'
    default_name = 'container_layer'
    default_opacity = 1.0

    def ApplyAttributes(self, attributes):
        uicls.NewContainer.ApplyAttributes(self, attributes)
        self.clearBackground = True
        self.backgroundColor = (0, 0, 0, 0)
        opacity = attributes.get('opacity', self.default_opacity)
        if (opacity is not None):
            self.SetOpacity(opacity)



    def OnSetAttr(self, k, v):
        uicls.NewContainer.OnSetAttr(self, k, v)
        if (k == 'opacity'):
            self.SetOpacity(v)



    def __getattr__(self, k):
        if (k == 'opacity'):
            return self.color[3]
        else:
            return uicls.Container.__getattr__(self, k)



    def SetOpacity(self, opacity):
        (r, g, b, a,) = self.color
        self.color = (r,
         g,
         b,
         opacity)



    def GetOpacity(self):
        return self.color[3]




